*****Conscription and Military Service: Do They Result in Future Violent and Non-Violent Incarcerations and Recidivism?  Wang, Flores-Lagunes 2020*****

cd "C:\Users\xinto\Dropbox\Vietnam Veteran Paper\Crime Paper\2020 JHR Data\1. Main Dataset"

set more off
clear all
set memory 350m
set matsize 800

*****1979: State Survey******
****1979 State Survey****
clear
use SISFC1979

***Study***
gen study=1979

***ID***
gen id=V5

***Male***
tab V6
gen male=9
replace male=1 if V6==1 
replace male=0 if V6==2 
tab male

***Final Weight***
gen weight=V4
egen total_male_inmate=total(weight) if male==1 

***Birth Month***
tab V7, nol
gen birthMonth=99
replace birthMonth=V7 if V7!=99 & V7!=0
tab birthMonth

***Birth Day***
tab V8, nol
gen birthDay=99
replace birthDay=V8 if V8!=99 & V8!=98
tab birthDay

***Birth Year***
tab V9, nol
gen birthYear=99 
replace birthYear=V9 if V9!=99 & V9!=98
tab birthYear

***Age (no missing values)***
tab V11, nol
gen age=V11 

***White***
tab V13, nol
gen white=9 
replace white=1 if V13==1
replace white=0 if (V13==2 | V13==3 | V13==4 | V13==5 | V13==6 | V13==7 )

****Married (no missing values)****
tab V12, nol
gen married=9
replace married=1 if V12==1
replace married=0 if V12!=1 

***Divorced (no missing values)***
tab V12, nol
gen divorced=9
replace divorced=1 if V12==3
replace divorced=0 if V12!=3 

***Never Married***
gen neverMarried=9
replace neverMarried=1 if V12==5
replace neverMarried=0 if V12!=5 




***Ever served in the military***
tab V428, nol
gen armForce=9 
replace armForce=1 if V428==1
replace armForce=0 if V428==2

***Serve Branches*** 
tab V434
gen serveBranch=V434

***Serve in Army***
gen army=9
replace army=1 if V434==1
replace army=0 if V434!=1 & V434!=9 & V19!=0

***Month Enter Military***
tab V429, nol
gen monthEnterMilitary=99
replace  monthEnterMilitary=V429 if V429!=0 & V429!=99 & V429!=13 & V429!=98

***Year Enter Military***
tab V430, nol
gen yearEnterMilitary=99 
replace yearEnterMilitary=V430 if V430!=98 & V430!=99 & V430!=97

***Month Discharged Military***
tab V431, nol
gen monthDischargedMilitary=99
replace monthDischargedMilitary=V431 if V431!=0 & V431!=99 & V431!=13

***Year Discharged Military***
tab V432, nol
gen yearDischargedMilitary=99
replace yearDischargedMilitary=V432 if V432!=98 & V432!=99
 
***Member of National Goard***
tab V435
gen memberReserve=9 
replace memberReserve=1 if V435==1
replace memberReserve=0 if V435==2

***Stationed in Vietnam***
tab V437 
gen stationedVietnam=9
replace stationedVietnam=1 if V437==1
replace stationedVietnam=0 if V437==2 | V428==2
tab stationedVietnam

***Eligible for VA Benefits or Education***
tab V438
gen eligibleVA=9
replace eligibleVA=1 if V438==1 
replace eligibleVA=0 if V438==2 

***Month of Admission***
tab V928, nol
gen admissionMonth=99
replace admissionMonth=V928 if V928!=98 & V928!=0 

***Year of Admission***
tab V929, nol
gen admissionYear=99
replace admissionYear=V929 if V929!=99 

***Current Offense 1 (No missing data)***
tab V930, nol
gen currentOffense1=V930

***Current Offense 2 (No missing data) ***
tab V931, nol
gen currentOffense2=V931

***Current Offense 3***
tab V932, nol
gen currentOffense3=V932

***Current Offense 4***
tab V933, nol
gen currentOffense4=V933



***Lindo and Stoecker Offense 1 ***
tab V30, nol
gen LScurrentOffense1=V30

***Lindo and Stoecker Offense 2 ***
tab V31, nol
gen LScurrentOffense2=V31

***Lindo and Stoecker Offense 3 ***
tab V32, nol
gen LScurrentOffense3=V32

***Lindo and Stoecker Offense 4***
tab V33, nol
gen LScurrentOffense4=V33



***************Prior Sentences***************
tab V939, nol
gen priorIncarceration=9
replace priorIncarceration=1 if V939==2
replace priorIncarceration=0 if V939==1
tab priorIncarceration

***Ever on Probation***
tab V216, nol
gen everProbation=9
replace everProbation=1 if V216==1 
replace everProbation=0 if V216==2 

***Times on Probation as Juvenile***
tab V217, nol
gen timesProbationJuv=999
replace timesProbationJuv=V217 if V217!=997 & V217!=998 & V217!=999

/***age first on Probation as Juvenile***
tab V250 
gen ageProbationJuv=V250
replace ageProbationJuv=999 if ageProbationJuv==998


***Offense 1 on Probation as Juvenile***
tab V191,nol
gen firstProbOffenseJuv1=999
replace firstProbOffenseJuv1=V191 if V191!=998 & V191!=997

***Offense 2 on Probation as Juvenile***
tab V192, nol
gen firstProbOffenseJuv2=V192
replace firstProbOffenseJuv2=999 if firstProbOffenseJuv2==998
replace firstProbOffenseJuv2=999 if firstProbOffenseJuv2==997

***Offense 3 on Probation as Juvenile***
tab V193, nol
gen firstProbOffenseJuv3=V193
replace firstProbOffenseJuv3=999 if firstProbOffenseJuv3==998
replace firstProbOffenseJuv3=999 if firstProbOffenseJuv3==997

***Offense 4 on Probation as Juvenile***
tab V194, nol
gen firstProbOffenseJuv4=V194
replace firstProbOffenseJuv4=999 if firstProbOffenseJuv4==998
replace firstProbOffenseJuv4=999 if firstProbOffenseJuv4==997

***Offense 5 on Probation as Juvenile***
tab V195, nol
gen firstProbOffenseJuv5=V195
replace firstProbOffenseJuv5=999 if firstProbOffenseJuv5==998
replace firstProbOffenseJuv5=999 if firstProbOffenseJuv5==997
*/ 

***Times on Probation as Adult***
tab V218, nol
gen timesProbationAdu=999
replace timesProbationAdu=V218 if V218!=998 & V218!=999

***Age first on Probation***
tab V219, nol
gen ageProbation=999
replace ageProbation=V219 if V219!=997 & V219!=998 & V219!=999

***Serve for Drunkeness***
tab V220, nol
gen servDrunk=9
replace servDrunk=1 if V220==1 
replace servDrunk=0 if V220==2 

***Times as a Juvenile: Serve for Drunkeness***
tab V221, nol
gen timesDrunkAsJuv=999
replace timesDrunkAsJuv=V221 if V221!=997 & V221!=998 & V221!=999

***Times for Drunkeness as Adult***
tab V222, nol
gen timesDrunkAsAdu=999
replace timesDrunkAsAdu=V222 if V222!=997 & V222!=998 & V222!=999

***Serve Other Than Drunkeness***
tab V223, nol
gen servOther=9 
replace servOther=1 if V223==1
replace servOther=0 if V223==2

***Serve times for Others as Juvenile***
tab V224, nol
gen timesOtherJuv=999
replace timesOtherJuv=V224 if V224!=997 & V224!=998 & V224!=999

***Serve times for Others as Adult***
tab V225, nol
gen timesOtherAdu=999
replace timesOtherAdu=V225 if V225!=997 & V225!=998 & V225!=999

***First serve offense 1***
tab V226, nol
gen firstServeOffense1=V226
replace firstServeOffense1=99 if firstServeOffense1==0
replace firstServeOffense1=99 if firstServeOffense1==98
tab firstServeOffense1
***First serve offense 2***
tab V227, nol
gen firstServeOffense2=V227
replace firstServeOffense2=99 if firstServeOffense2==0
replace firstServeOffense2=99 if firstServeOffense2==98
tab firstServeOffense2
***First serve offense 3***
tab V228, nol
gen firstServeOffense3=V228
replace firstServeOffense3=99 if firstServeOffense3==0
replace firstServeOffense3=99 if firstServeOffense3==98
tab firstServeOffense3
***First serve offense 4***
tab V229, nol
gen firstServeOffense4=V229
replace firstServeOffense4=99 if firstServeOffense4==0
replace firstServeOffense4=99 if firstServeOffense4==98
tab firstServeOffense4
***First serve admission Month***
tab V230, nol
gen firstAdmitMonth=99
replace firstAdmitMonth=V230 if V230!=0 & V230!=13 & V230!=98 
tab firstAdmitMonth
***First serve admission Year***
tab V231, nol
gen firstAdmitYear=99
replace firstAdmitYear=V231 if V231!=97 & V231!=98 
tab firstAdmitYear
***First serve as adult***
tab V234
gen firstServeAdult=9
replace firstServeAdult=1 if V234==2 
replace firstServeAdult=0 if V234==1 
tab firstServeAdult


***Second serve offense 1***
tab V244, nol
gen secondServeOffense1=V244
replace secondServeOffense1=99 if secondServeOffense1==0
replace secondServeOffense1=99 if secondServeOffense1==98
tab secondServeOffense1
***Second serve offense 2***
tab V245, nol
gen secondServeOffense2=V245
replace secondServeOffense2=99 if secondServeOffense2==0
replace secondServeOffense2=99 if secondServeOffense2==98
tab secondServeOffense2
***Second serve offense 3***
tab V246, nol
gen secondServeOffense3=V246
replace secondServeOffense3=99 if secondServeOffense3==0
replace secondServeOffense3=99 if secondServeOffense3==98
tab secondServeOffense3
***Second serve offense 4***
tab V247, nol
gen secondServeOffense4=V247
replace secondServeOffense4=99 if secondServeOffense4==0
replace secondServeOffense4=99 if secondServeOffense4==98
tab secondServeOffense4
***Second serve admission Month***
tab V248, nol
gen secondAdmitMonth=99
replace secondAdmitMonth=V248 if V248!=0 & V248!=13 & V248!=98 
tab secondAdmitMonth
***Second serve admission Year***
tab V249, nol
gen secondAdmitYear=99
replace secondAdmitYear=V249 if V249!=97 & V249!=98 
tab secondAdmitYear
***Second serve as adult***
tab V252
gen secondServeAdult=9
replace secondServeAdult=1 if V252==2 
replace secondServeAdult=0 if V252==1 
tab secondServeAdult



***Third serve offense 1***
tab V262, nol
gen thirdServeOffense1=V262
replace thirdServeOffense1=99 if thirdServeOffense1==0
replace thirdServeOffense1=99 if thirdServeOffense1==98
tab thirdServeOffense1
***Third serve offense 2***
tab V263, nol
gen thirdServeOffense2=V263
replace thirdServeOffense2=99 if thirdServeOffense2==0
replace thirdServeOffense2=99 if thirdServeOffense2==98
tab thirdServeOffense2
***Third serve offense 3***
tab V264, nol
gen thirdServeOffense3=V264
replace thirdServeOffense3=99 if thirdServeOffense3==0
replace thirdServeOffense3=99 if thirdServeOffense3==98
tab thirdServeOffense3
***Third serve offense 4***
tab V265, nol
gen thirdServeOffense4=V265
replace thirdServeOffense4=99 if thirdServeOffense4==0
replace thirdServeOffense4=99 if thirdServeOffense4==98
tab thirdServeOffense4
***Third serve admission Month***
tab V266, nol
gen thirdAdmitMonth=99
replace thirdAdmitMonth=V266 if V266!=0 & V266!=13 & V266!=98 
tab thirdAdmitMonth
***Third serve admission Year***
tab V267, nol
gen thirdAdmitYear=99
replace thirdAdmitYear=V267 if V267!=97 & V267!=98 
tab thirdAdmitYear
***Third serve as adult***
tab V270, nol
gen thirdServeAdult=9
replace thirdServeAdult=1 if V270==2 
replace thirdServeAdult=0 if V270==1 
tab thirdServeAdult


***Fourth serve offense 1***
tab V280, nol
gen fourthServeOffense1=V280
replace fourthServeOffense1=99 if fourthServeOffense1==0
replace fourthServeOffense1=99 if fourthServeOffense1==98
tab fourthServeOffense1
***Fourth serve offense 2***
tab V281, nol
gen fourthServeOffense2=V281
replace fourthServeOffense2=99 if fourthServeOffense2==0
replace fourthServeOffense2=99 if fourthServeOffense2==98
tab fourthServeOffense2
***Fourth serve offense 3***
tab V282, nol
gen fourthServeOffense3=V282
replace fourthServeOffense3=99 if fourthServeOffense3==0
replace fourthServeOffense3=99 if fourthServeOffense3==98
tab fourthServeOffense3
***Fourth serve offense 4***
tab V283, nol
gen fourthServeOffense4=V283
replace fourthServeOffense4=99 if fourthServeOffense4==0
replace fourthServeOffense4=99 if fourthServeOffense4==98
tab fourthServeOffense4
***Fourth serve admission Month***
tab V284, nol
gen fourthAdmitMonth=99
replace fourthAdmitMonth=V284 if V284!=0 & V284!=13 & V284!=98 
tab fourthAdmitMonth
***Fourth serve admission Year***
tab V285, nol
gen fourthAdmitYear=99
replace fourthAdmitYear=V285 if V285!=97 & V285!=98 
tab fourthAdmitYear
***Fourth serve as adult***
tab V288, nol
gen fourthServeAdult=9
replace fourthServeAdult=1 if V288==2 
replace fourthServeAdult=0 if V288==1 
tab fourthServeAdult


***Fifth serve offense 1***
tab V298, nol
gen fifthServeOffense1=V298
replace fifthServeOffense1=99 if fifthServeOffense1==0
replace fifthServeOffense1=99 if fifthServeOffense1==98
tab fifthServeOffense1
***Fifth serve offense 2***
tab V299, nol
gen fifthServeOffense2=V299
replace fifthServeOffense2=99 if fifthServeOffense2==0
replace fifthServeOffense2=99 if fifthServeOffense2==98
tab fifthServeOffense2
***Fifth serve offense 3***
tab V300, nol
gen fifthServeOffense3=V300
replace fifthServeOffense3=99 if fifthServeOffense3==0
replace fifthServeOffense3=99 if fifthServeOffense3==98
tab fifthServeOffense3
***Fifth serve offense 4***
tab V301, nol
gen fifthServeOffense4=V301
replace fifthServeOffense4=99 if fifthServeOffense4==0
replace fifthServeOffense4=99 if fifthServeOffense4==98
tab fifthServeOffense4
***Fifth serve admission Month***
tab V302, nol
gen fifthAdmitMonth=99
replace fifthAdmitMonth=V302 if V302!=0 & V302!=13 & V302!=98 
tab fifthAdmitMonth
***Fifth serve admission Year***
tab V303, nol
gen fifthAdmitYear=99
replace fifthAdmitYear=V303 if V303 !=97 & V303 !=98 
tab fifthAdmitYear
***Fifth serve as adult***
tab V306, nol
gen fifthServeAdult=9
replace fifthServeAdult=1 if V306==2 
replace fifthServeAdult=0 if V306==1 
tab fifthServeAdult


***Sixth serve offense 1***
tab V316, nol
gen sixthServeOffense1=V316
replace sixthServeOffense1=99 if sixthServeOffense1==0
replace sixthServeOffense1=99 if sixthServeOffense1==98
tab sixthServeOffense1
***Sixth serve offense 2***
tab V317, nol
gen sixthServeOffense2=V317
replace sixthServeOffense2=99 if sixthServeOffense2==0
replace sixthServeOffense2=99 if sixthServeOffense2==98
tab sixthServeOffense2
***Sixth serve offense 3***
tab V318, nol
gen sixthServeOffense3=V318
replace sixthServeOffense3=99 if sixthServeOffense3==0
replace sixthServeOffense3=99 if sixthServeOffense3==98
tab sixthServeOffense3
***Sixth serve offense 4***
tab V319, nol
gen sixthServeOffense4=V319
replace sixthServeOffense4=99 if sixthServeOffense4==0
replace sixthServeOffense4=99 if sixthServeOffense4==98
tab sixthServeOffense4
***Sixth serve admission Month***
tab V320, nol
gen sixthAdmitMonth=99
replace sixthAdmitMonth=V320 if V320!=0 & V320!=13 & V320!=98 
tab sixthAdmitMonth
***Sixth serve admission Year***
tab V321, nol
gen sixthAdmitYear=99
replace sixthAdmitYear=V321 if V321!=97 & V321 !=98 
tab sixthAdmitYear
***Sixth serve as adult***
tab V324, nol
gen sixthServeAdult=9
replace sixthServeAdult=1 if V324==2 
replace sixthServeAdult=0 if V324==1 
tab sixthServeAdult



***Seventh serve offense 1***
tab V334, nol
gen seventhServeOffense1=V334
replace seventhServeOffense1=99 if seventhServeOffense1==0
replace seventhServeOffense1=99 if seventhServeOffense1==98
tab seventhServeOffense1
***Seventh serve offense 2***
tab V335, nol
gen seventhServeOffense2=V335
replace seventhServeOffense2=99 if seventhServeOffense2==0
replace seventhServeOffense2=99 if seventhServeOffense2==98
tab seventhServeOffense2
***Seventh serve offense 3***
tab V336, nol
gen seventhServeOffense3=V336
replace seventhServeOffense3=99 if seventhServeOffense3==0
replace seventhServeOffense3=99 if seventhServeOffense3==98
tab seventhServeOffense3
***Seventh serve offense 4***
tab V337, nol
gen seventhServeOffense4=V337
replace seventhServeOffense4=99 if seventhServeOffense4==0
replace seventhServeOffense4=99 if seventhServeOffense4==98
tab seventhServeOffense4
***Seventh serve admission Month***
tab V338, nol
gen seventhAdmitMonth=99
replace seventhAdmitMonth=V338 if V338!=0 & V338!=13 & V338!=98 
tab seventhAdmitMonth
***Seventh serve admission Year***
tab V339, nol
gen seventhAdmitYear=99
replace seventhAdmitYear=V339 if V339!=97 & V339!=98 
tab seventhAdmitYear
***Seventh serve as adult***
tab V342, nol
gen seventhServeAdult=9
replace seventhServeAdult=1 if V342==2 
replace seventhServeAdult=0 if V342==1 
tab seventhServeAdult


***Eighth serve offense 1***
tab V352, nol
gen eighthServeOffense1=V352
replace eighthServeOffense1=99 if eighthServeOffense1==0
replace eighthServeOffense1=99 if eighthServeOffense1==98
tab eighthServeOffense1
***Eighth serve offense 2***
tab V353, nol
gen eighthServeOffense2=V353
replace eighthServeOffense2=99 if eighthServeOffense2==0
replace eighthServeOffense2=99 if eighthServeOffense2==98
tab eighthServeOffense2
***Eighth serve offense 3***
tab V354, nol
gen eighthServeOffense3=V354
replace eighthServeOffense3=99 if eighthServeOffense3==0
replace eighthServeOffense3=99 if eighthServeOffense3==98
tab eighthServeOffense3
***Eighth serve offense 4***
tab V355, nol
gen eighthServeOffense4=V355
replace eighthServeOffense4=99 if eighthServeOffense4==0
replace eighthServeOffense4=99 if eighthServeOffense4==98
tab eighthServeOffense4
***Eighth serve admission Month***
tab V356, nol
gen eighthAdmitMonth=99
replace eighthAdmitMonth=V356 if V356!=0 & V356!=13 & V356!=98 
tab eighthAdmitMonth
***Eighth serve admission Year***
tab V357, nol
gen eighthAdmitYear=99
replace eighthAdmitYear=V357 if V357!=97 & V357!=98 
tab eighthAdmitYear
***Eighth serve as adult***
tab V360, nol
gen eighthServeAdult=9
replace eighthServeAdult=1 if V360==2 
replace eighthServeAdult=0 if V360==1 
tab eighthServeAdult



***Ninth serve offense 1***
tab V370, nol
gen ninthServeOffense1= V370
replace ninthServeOffense1=99 if ninthServeOffense1==0
replace ninthServeOffense1=99 if ninthServeOffense1==98
tab ninthServeOffense1
***Ninth serve offense 2***
tab V371, nol
gen ninthServeOffense2=V371
replace ninthServeOffense2=99 if ninthServeOffense2==0
replace ninthServeOffense2=99 if ninthServeOffense2==98
tab ninthServeOffense2
***Ninth serve offense 3***
tab V372, nol
gen ninthServeOffense3=V372
replace ninthServeOffense3=99 if ninthServeOffense3==0
replace ninthServeOffense3=99 if ninthServeOffense3==98
tab ninthServeOffense3
***Ninth serve offense 4***
tab V373, nol
gen ninthServeOffense4=V373
replace ninthServeOffense4=99 if ninthServeOffense4==0
replace ninthServeOffense4=99 if ninthServeOffense4==98
tab ninthServeOffense4
***Ninth serve admission Month***
tab V374, nol
gen ninthAdmitMonth=99
replace ninthAdmitMonth=V374 if V374!=0 & V374!=13 & V374!=98 
tab ninthAdmitMonth
***Ninth serve admission Year***
tab V375, nol
gen ninthAdmitYear=99
replace ninthAdmitYear=V375 if V375!=97 & V375!=98 
tab ninthAdmitYear
***Ninth serve as adult***
tab V378, nol
gen ninthServeAdult=9
replace ninthServeAdult=1 if V378==2 
replace ninthServeAdult=0 if V378==1 
tab ninthServeAdult


***Tenth serve offense 1***
tab V388, nol
gen tenthServeOffense1= V388
replace tenthServeOffense1=99 if tenthServeOffense1==0
replace tenthServeOffense1=99 if tenthServeOffense1==98
tab tenthServeOffense1
***Tenth serve offense 2***
tab V389, nol
gen tenthServeOffense2=V389
replace tenthServeOffense2=99 if tenthServeOffense2==0
replace tenthServeOffense2=99 if tenthServeOffense2==98
tab tenthServeOffense2
***Tenth serve offense 3***
tab V390, nol
gen tenthServeOffense3=V390
replace tenthServeOffense3=99 if tenthServeOffense3==0
replace tenthServeOffense3=99 if tenthServeOffense3==98
tab tenthServeOffense3
***Tenth serve offense 4***
tab V391, nol
gen tenthServeOffense4=V391
replace tenthServeOffense4=99 if tenthServeOffense4==0
replace tenthServeOffense4=99 if tenthServeOffense4==98
tab tenthServeOffense4
***Tenth serve admission Month***
tab V392, nol
gen tenthAdmitMonth=99
replace tenthAdmitMonth=V392 if V392!=0 & V392!=13 & V392!=98 
tab tenthAdmitMonth
***Tenth serve admission Year***
tab V393, nol
gen tenthAdmitYear=99
replace tenthAdmitYear=V393 if V393!=97 & V393!=98 
tab tenthAdmitYear
***Tenth serve as adult***
tab V396, nol
gen tenthServeAdult=9
replace tenthServeAdult=1 if V396==2 
replace tenthServeAdult=0 if V396==1 
tab tenthServeAdult



***Eleventh serve offense 1***
tab V940, nol
gen eleventhServeOffense1=V940
replace eleventhServeOffense1=99 if eleventhServeOffense1==0
replace eleventhServeOffense1=99 if eleventhServeOffense1==98
tab eleventhServeOffense1
***Eleventh serve offense 2***
tab V941, nol
gen eleventhServeOffense2=V941
replace eleventhServeOffense2=99 if eleventhServeOffense2==0
replace eleventhServeOffense2=99 if eleventhServeOffense2==98
tab eleventhServeOffense2
***Eleventh serve offense 3***
tab V942, nol
gen eleventhServeOffense3=V942
replace eleventhServeOffense3=99 if eleventhServeOffense3==0
replace eleventhServeOffense3=99 if eleventhServeOffense3==98
tab eleventhServeOffense3
***Eleventh serve offense 4***
tab V943, nol
gen eleventhServeOffense4=V943
replace eleventhServeOffense4=99 if eleventhServeOffense4==0
replace eleventhServeOffense4=99 if eleventhServeOffense4==98
tab eleventhServeOffense4
***Eleventh serve admission Month***
tab V944, nol
gen eleventhAdmitMonth=99
replace eleventhAdmitMonth=V944 if V944!=0 & V944!=13 & V944!=98 
tab eleventhAdmitMonth
***Eleventh serve admission Year***
tab V945, nol
gen eleventhAdmitYear=99
replace eleventhAdmitYear=V945 if V945!=97 & V945!=98 
tab eleventhAdmitYear
***Eleventh serve as adult***
tab V948, nol
gen eleventhServeAdult=9
replace eleventhServeAdult=1 if V948==2 
replace eleventhServeAdult=0 if V948==1 
tab eleventhServeAdult



***Twelfth serve offense 1***
tab V958, nol
gen twelfthServeOffense1=V958
replace twelfthServeOffense1=99 if twelfthServeOffense1==0
replace twelfthServeOffense1=99 if twelfthServeOffense1==98
tab twelfthServeOffense1
***Twelfth serve offense 2***
tab V959, nol
gen twelfthServeOffense2=V959
replace twelfthServeOffense2=99 if twelfthServeOffense2==0
replace twelfthServeOffense2=99 if twelfthServeOffense2==98
tab twelfthServeOffense2
***Twelfth serve offense 3***
tab V960, nol
gen twelfthServeOffense3=V960
replace twelfthServeOffense3=99 if twelfthServeOffense3==0
replace twelfthServeOffense3=99 if twelfthServeOffense3==98
tab twelfthServeOffense3
***Twelfth serve offense 4***
tab V961, nol
gen twelfthServeOffense4=V961
replace twelfthServeOffense4=99 if twelfthServeOffense4==0
replace twelfthServeOffense4=99 if twelfthServeOffense4==98
tab twelfthServeOffense4
***Twelfth serve admission Month***
tab V962, nol
gen twelfthAdmitMonth=99
replace twelfthAdmitMonth=V962 if V962!=0 & V962!=13 & V962!=98 
tab twelfthAdmitMonth
***Twelfth serve admission Year***
tab V963, nol
gen twelfthAdmitYear=99
replace twelfthAdmitYear=V963 if V963!=97 & V963!=98 
tab twelfthAdmitYear
***Twelfth serve as adult***
tab V966, nol
gen twelfthServeAdult=9
replace twelfthServeAdult=1 if V966==2 
replace twelfthServeAdult=0 if V966==1 
tab twelfthServeAdult


***Thirteeth serve offense 1***
tab V976, nol
gen thirteethServeOffense1=V976
replace thirteethServeOffense1=99 if thirteethServeOffense1==0
replace thirteethServeOffense1=99 if thirteethServeOffense1==98
tab thirteethServeOffense1
***Thirteeth serve offense 2***
tab V977, nol
gen thirteethServeOffense2=V977
replace thirteethServeOffense2=99 if thirteethServeOffense2==0
replace thirteethServeOffense2=99 if thirteethServeOffense2==98
tab thirteethServeOffense2
***Thirteeth serve offense 3***
tab V978, nol
gen thirteethServeOffense3=V978
replace thirteethServeOffense3=99 if thirteethServeOffense3==0
replace thirteethServeOffense3=99 if thirteethServeOffense3==98
tab thirteethServeOffense3
***Thirteeth serve offense 4***
tab V979, nol
gen thirteethServeOffense4=V979
replace thirteethServeOffense4=99 if thirteethServeOffense4==0
replace thirteethServeOffense4=99 if thirteethServeOffense4==98
tab thirteethServeOffense4
***Thirteeth serve admission Month***
tab V980, nol
gen thirteethAdmitMonth=99
replace thirteethAdmitMonth=V980 if V980!=0 & V980!=13 & V980!=98 
tab thirteethAdmitMonth
***Thirteeth serve admission Year***
tab V981, nol
gen thirteethAdmitYear=99
replace thirteethAdmitYear=V981 if V981!=97 & V981!=98 
tab thirteethAdmitYear
***Thirteeth serve as adult***
tab V984, nol
gen thirteethServeAdult=9
replace thirteethServeAdult=1 if V984==2 
replace thirteethServeAdult=0 if V984==1 
tab thirteethServeAdult

*****Social Economic Status*****
****has GED or Highschool Equivalent****
tab V495
gen hasGedEqui=9
replace hasGedEqui=1 if V495==1
replace hasGedEqui=0 if V495==2
tab hasGedEqui
***Highest Grade Attended (no missing data)*** 
tab V491
gen topGradeAttended=V491
tab topGradeAttended
***Highest Grade Completed***
tab V492
gen topGradeCompleted=99
replace topGradeCompleted=topGradeAttended if (V492==1 | V491==0) 
replace topGradeCompleted=topGradeAttended-1 if (V492==2|V492==3) & V491!=0
tab topGradeCompleted
***Completed high school***
gen completeHighSchool=9
replace completeHighSchool=1 if topGradeCompleted>=12
replace completeHighSchool=0 if topGradeCompleted<12
tab completeHighSchool
***Any Formal Training or Job Skills***
gen formalTraining=9
replace formalTraining=1 if V496==1 
replace formalTraining=0 if V496==2
tab formalTraining
***Job before Offense***
tab V512
gen jobAtOffense=9
replace jobAtOffense=1 if (V512==2 | V512==3) 
replace jobAtOffense=0 if  V512==1
tab jobAtOffense
***Full Time Job***
gen fullTimeJob=9
replace fullTimeJob=1 if V512==2 
replace fullTimeJob=0 if (V512==1 | V512==3)
tab fullTimeJob
***Looking for Job***
tab V513
gen lookForJob=9
replace lookForJob=1 if V513==1 
replace lookForJob=0 if V513==2
***Major Reason not Looking for Jobs***
gen reasonNotLooking=99 
replace reasonNotLooking=V529 if V529!=0
***Year last worked at a job***
gen yearLastWorked=99
replace yearLastWorked=V531 if V531!=0 

***Free at least for one year before admission*** 
tab V536
gen freeAYear=9
replace freeAYear=1 if V536==1
replace freeAYear=0 if (V536==2|V536==3)
***Monthly Income Received ***
tab V537
gen monthIncome=9999999
replace monthIncome=V537 if V537!=9999998 
***Annual Income***
tab V539 
gen annualIncome=9999999
replace annualIncome=0 if V539==0 
replace annualIncome=500 if V539==1 
replace annualIncome=1500 if V539==2 
replace annualIncome=2500 if V539==3 
replace annualIncome=4000 if V539==4 
replace annualIncome=7500 if V539==5 
replace annualIncome=12500 if V539==6
replace annualIncome=17500 if V539==7
replace annualIncome=22500 if V539==8 
replace annualIncome=25000 if V539==9 
tab annualIncome
***When free, receiving wage***
tab V540, nol
gen receiveWage=9
replace receiveWage=1 if V540==1
replace receiveWage=0 if V540==0 
tab receiveWage
***When free, receiving SSI, welfare, UI
gen receiveSsi=9
replace receiveSsi=1 if (V541==2 | V542==3 | V543==4)
replace receiveSsi=0 if (V541==0 & V542==0 & V543==0) 
tab receiveSsi
***When free, receiving from family and friends***
tab V544, nol
gen receiveFAndF=9
replace receiveFAndF=1 if V544==5 
replace receiveFAndF=0 if V544==0 
tab receiveFAndF
***When free, receiving illegal income***
tab V546, nol
gen receiveIllegalIncome=9
replace receiveIllegalIncome=1 if V546==7 
replace receiveIllegalIncome=0 if V546==0 
tab receiveIllegalIncome
***When free, receiving anything else***
tab V545
gen receiveAnythingElse=9
replace receiveAnythingElse=1 if V545==6
replace receiveAnythingElse=0 if V545==0 
tab receiveAnythingElse

***Support Someone Before Arrest***
tab V547
gen supportOthersBeforeArrest=9
replace supportOthersBeforeArrest=1 if V547>=1 & V547<=99
replace supportOthersBeforeArrest=0 if V547==0
tab supportOthersBeforeArrest

***Number of Brothers and sisters***
tab V569
gen numberSiblings=999
replace numberSiblings=V569 if V569!=998 & V569!=999
tab numberSiblings

***Oldest Child***
tab V571 
gen oldestChild=9
replace oldestChild=1 if V571==1
replace oldestChild=0 if V571==2

***Highest Grade Mother Attended***
tab V578, nol
gen higestGradeMother=99
replace higestGradeMother=V578 if V578!=97 & V578!=98 & V578!=99
tab higestGradeMother

***Highest Grade Father Attended***
tab V582, nol 
gen higestGradeFather=99
replace higestGradeFather=V582 if V582!=97 & V582!=98 & V582!=99
tab higestGradeFather

***Anyone in family ever served***
tab V585, nol
gen familyServed=9
replace familyServed=1 if V586==2 | V587==3 | V588==4 | V589==5
replace familyServed=0 if V585==1
tab familyServed

***Mother served before***
tab V586, nol
gen motherServed=9
replace motherServed=1 if V586==2 
replace motherServed=0 if V586!=2 

***Father served before***
tab V587, nol
gen fatherServed=9
replace fatherServed=1 if V587==3 
replace fatherServed=0 if V587!=3 
tab fatherServed

***Who grow up with: Mother only*** 
tab V592, nol
gen growUpMotherOnly=9
replace growUpMotherOnly=1 if V592==1 
replace growUpMotherOnly=0 if V592!=1 & V592!=0
tab growUpMotherOnly

***Who grow up with: Father only*** 
gen growUpFatherOnly=9
replace growUpFatherOnly=1 if V592==2 
replace growUpFatherOnly=0 if V592!=2 & V592!=0
tab growUpFatherOnly

***Who grow up with: both parents*** 
gen growUpBothParents=9
replace growUpBothParents=1 if V592==3 
replace growUpBothParents=0 if V592!=3 & V592!=0
tab growUpBothParents

***Who grow up with: Grandparents*** 
gen growUpGrandParents=9
replace growUpGrandParents=1 if V592==4
replace growUpGrandParents=0 if V592!=4 & V592!=0
tab growUpGrandParents

***Who grow up with: Other relatives*** 
gen growUpOtherRelatives=9
replace growUpOtherRelatives=1 if V592==5
replace growUpOtherRelatives=0 if V592!=5 & V592!=0
tab growUpOtherRelatives

***Who grow up with: Friends*** 
gen growUpFriends=9
replace growUpFriends=1 if V592==7
replace growUpFriends=0 if V592!=7 & V592!=0
tab  growUpFriends

***Who grow up with: Foster homes and institutions*** 
gen growUpFosterInst=9
replace growUpFosterInst=1 if V592==7 | V592==8
replace growUpFosterInst=0 if V592!=7 & V592!=8 & V592!=0
tab growUpFosterInst

***Who grow up with: Somewhere else*** 
gen growUpElse=9
replace growUpElse=1 if V592==9
replace growUpElse=0 if V592!=9 & V592!=0
tab growUpElse

***Have Children***
tab V555, nol
gen haveChildren=9 
replace haveChildren=1 if V555>=1 & V555<=100
replace haveChildren=0 if V555==0
tab haveChildren

***Ever use any drugs***
tab V611, nol 
tab V627, nol 
tab V643, nol
tab V659, nol
tab V675, nol 
tab V691, nol 
tab V707, nol 
tab V723, nol 
tab V739, nol 

gen everUseDrug=9 
replace everUseDrug=1 if V611==1 
replace everUseDrug=1 if V627==1 
replace everUseDrug=1 if V643==1
replace everUseDrug=1 if V659==1
replace everUseDrug=1 if V675==1 
replace everUseDrug=1 if V691==1 
replace everUseDrug=1 if V707==1 
replace everUseDrug=1 if V723==1 
replace everUseDrug=1 if V739==1 

replace everUseDrug=0 if (V611==2 & V627==2 & V643==2 & V659==2 & /// 
V675==2 & V691==2 & V707==2 & V723==2 & V739==2 )

tab everUseDrug

***Age First Use Drugs on regular or daily base***
tab V613, nol 
tab V618, nol 
tab V629, nol 
tab V634, nol
tab V645, nol 
tab V650, nol 
tab V661, nol 
tab V666, nol 
tab V677, nol 
tab V682, nol 
tab V693, nol 
tab V698, nol 
tab V709, nol 
tab V714, nol 
tab V725, nol 
tab V730, nol 
tab V741, nol 
tab V746, nol 

***Age first use Heroin***
gen ageFirstUseHeroin=999
replace ageFirstUseHeroin=min(V613, V618) if ((V613>0 & V613<998) | (V618>0 & V618<998))
tab ageFirstUseHeroin
***Age first use Methadone***
gen ageFirstUseMeth=999
replace ageFirstUseMeth=min(V629, V634) if ((V629>0 & V629<998) | (V634>0 & V634<998))
tab ageFirstUseMeth
***Age first use Cocaine***
gen ageFirstUseCocaine=999
replace ageFirstUseCocaine=min(V645, V650) if ((V645>0 & V645<998) | (V650>0 & V650<998))
tab ageFirstUseCocaine
***Age first use Marijuana***
gen ageFirstUseMarijuana=999
replace ageFirstUseMarijuana=min(V661, V666) if ((V661>0 & V661<998) | (V661>0 & V666<998))
tab ageFirstUseMarijuana
***Age first use Amphetamine***
gen ageFirstUseAmphetamine=999
replace ageFirstUseAmphetamine=min(V677, V682) if ((V677>0 & V677<998) | (V682>0 & V682<998))
tab ageFirstUseAmphetamine
***Age first use Barbituat***
gen ageFirstUseBarbituat=999
replace ageFirstUseBarbituat=min(V693, V698) if ((V693>0 & V693<998) | (V698>0 & V698<998))
tab ageFirstUseBarbituat
***Age first use LSD***
gen ageFirstUseLsd=999
replace ageFirstUseLsd=min(V709, V714) if ((V709>0 & V709<998) | (V714>0 & V714<998))
tab ageFirstUseLsd
***Age first use PCP***
gen ageFirstUsePcp=999
replace ageFirstUsePcp=min(V725, V730) if ((V725>0 & V725<998) | (V730>0 & V730<998))
tab ageFirstUsePcp
***Age first use other drugs***
gen ageFirstUseOtherDrugs=999
replace ageFirstUseOtherDrugs=min(V741, V746) if ((V741>0 & V741<998) | (V746>0 & V746<998))
tab ageFirstUseOtherDrugs

***Age first use any drugs***
gen ageFirstUseAnyDrugs=999 
replace ageFirstUseAnyDrugs=min(ageFirstUseHeroin, ageFirstUseMeth, ageFirstUseCocaine, /// 
ageFirstUseMarijuana, ageFirstUseAmphetamine, ageFirstUseBarbituat, ageFirstUseLsd, /// 
ageFirstUsePcp, ageFirstUseOtherDrugs) 
tab ageFirstUseAnyDrugs 

***Whether using drugs before the current offense***
tab V622, nol
tab V638, nol
tab V654, nol
tab V670, nol 
tab V686, nol 
tab V702, nol 
tab V718, nol 
tab V734, nol
tab V750, nol

tab V611, nol 
tab V627, nol 
tab V643, nol
tab V659, nol
tab V675, nol 
tab V691, nol 
tab V707, nol 
tab V723, nol 
tab V739, nol 

gen useDrugBeforeCurrentOffense=9 
replace useDrugBeforeCurrentOffense=1 if (V622==1 | V638==1 | V654==1 | V670==1 | /// 
V686==1 | V702==1 | V718==1 | V734==1 | V750==1)
replace useDrugBeforeCurrentOffense=0 if ((V622==2 | V611==2) & (V638==2 | V627==2) /// 
& (V654==2| V643==2) & (V670==2 | V659==2) & (V686==2 | V675==2) & (V702==2| V691==2) /// 
& (V718==2| V707==2) & (V734==2 | V723==2) & (V750==2 | V739==2) )
 
tab useDrugBeforeCurrentOffense

***Whether using drugs before the first offense ***
tab V625, nol
tab V641, nol
tab V657, nol
tab V673, nol 
tab V689, nol 
tab V705, nol 
tab V721, nol 
tab V737, nol
tab V753, nol

gen useDrugBeforeFirstOffense=9 
replace useDrugBeforeFirstOffense=1 if (V625==1 | V641==1 | V657==1 | V673==1 | /// 
V689==1 | V705==1 | V721==1 | V737==1 | V753==1)
replace useDrugBeforeFirstOffense=0 if ((V625==2 | V611==2) & (V641==2 | V627==2) /// 
& (V657==2| V643==2) & (V673==2 | V659==2) & (V689==2 | V675==2) & (V705==2| V691==2) /// 
& (V721==2| V707==2) & (V737==2 | V723==2) & (V753==2 | V739==2) ) 

tab useDrugBeforeFirstOffense

***Whether participated in any drug treatment program 
tab V755, nol 
gen useDrugProgram=9
replace useDrugProgram=1 if V755==1 
replace useDrugProgram=0 if V755==2
tab useDrugProgram

***Under the influence of drug for the current offense 
tab V770, nol 
gen underDrugInfluence=9
replace underDrugInfluence=1 if V770==1 
replace underDrugInfluence=0 if V770==2
tab underDrugInfluence

save sisfcf_1979, replace 




























